﻿using System;

namespace Pfz.RemoteGaming.Internal
{
	internal struct _NotificationsDisablerForServer:
		IDisposable
	{
		private RemoteGameParticipant _participant;
		private bool _oldIsActive;
		public _NotificationsDisablerForServer(RemoteGameParticipant participant)
		{
			_participant = participant;
			_oldIsActive = participant._areNotificationsEnabled;
			participant._areNotificationsEnabled = false;
		}
		public void Dispose()
		{
			var participant = _participant;
			if (participant == null)
				return;

			_participant = null;
			if (_oldIsActive)
			{
				participant._areNotificationsEnabled = true;

				var room = participant.Room;
				if (room != null && room._started)
					room.ApplyChangesImmediately();
			}
		}
	}
}
